package com.atguigu.springcloud.service.impl;

import com.atguigu.springcloud.config.Result;
import com.atguigu.springcloud.dao.PaymentDao;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.IPaymentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * 支付接口
 *
 * @author zhenyu
 * @since 2022-08-26
 */
@Primary
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentDao, Payment>
    implements IPaymentService {

  @Value("${server.port}")
  private String serverPort;  //添加serverPort

  /**
   * 新增支付记录
   *
   * @param payment
   * @return
   */
  @Override
  public Result<String> create(Payment payment) {

    if (StringUtils.isNotBlank(payment.getSerial())) {
      this.baseMapper.insert(payment);
    }else {
      return Result.fail("新增失败,serverport:" + serverPort);
    }

    return Result.success("新增成功,serverport:" + serverPort);
  }

  /**
   * 查询支付记录
   *
   * @param id
   * @return
   */
  @Override
  public Payment getPaymentById(Long id) {

    //非空校验
    Assert.notNull(id,"id不能为空");

    return this.baseMapper.selectById(id);
  }
}
